<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" data-th-href="@{../static/bootstrap/css/bootstrap.min.css}">
<script src="../static/bootstrap/js/jquery-3.3.1.min.js "></script>
<script src="../static/bootstrap/js/bootstrap.min.js "></script>
<script src="../static/bootstrap-table/dist/bootstrap-table.js"></script>
<script	src="../static/bootstrap-table/dist/locale/bootstrap-table-zh-CN.js"></script>
<script src="../webjars/bootbox/4.4.0/bootbox.js"></script>
<style type="text/css">
	.ep_button{
		text-align:center; 
		margin-top: 7px;
	}
	#exampleInputName2{
		width: 300px;
	}
</style>
</head>
<body>
<div class="ep_button">
	<button type="button" class="btn btn-success" onclick="ep()" id="ep">剩余未安排的课表</button>
	<button type="button" class="btn btn-default" onclick="time()" id="time">剩余未安排的时间</button>
</div>
<div id="container" class="ep_button">
	 <form class="form-inline">
	  <div class="form-group">
	  	<input type="text" class="form-control" id="exampleInputName2" placeholder="搜索内容">
	  </div>
	  <button type="button" class="btn btn-default" id="sub1" onclick="search(1)">搜索</button>
	  <button type="button" class="btn btn-default" id="sub2" onclick="search(2)" style="display: none;">搜索</button>
	</form>
</div>
<div id="agcstable"></div>
<div id="timetable"></div>
</body>
<script type="text/javascript">
$(function(){
	$.post('../agcs/getMax',function(data){
		if(data=="no"){
			alert('课程已全部安排,也没有可以安排的课程');
			window.close();
		}
	});
	getWinto();
	
	//alert('课程已全部安排,也没有可以安排的课程');
	//window.close(); 
});
function search(value){
	var inpu=$("#exampleInputName2").val();
	if(value=="1"){
		getWinto(inpu);
	}else if(value=="2"){
		getTime(inpu);
	}
}
function ep(){
	$("#ep").attr("class", "");
	$("#ep").attr("class", "btn btn-success");
	$("#time").attr("class", "");
	$("#time").attr("class", "btn btn-default");
	$("#sub2").hide();
	$("#sub1").show();
	$('#exampleInputName2').val("");
	$("#timetable").html("");
	getWinto();
}
function time(){
	$("#ep").attr("class", "");
	$("#ep").attr("class", "btn btn-default");
	$("#time").attr("class", "");
	$("#time").attr("class", "btn btn-success");
	$('#exampleInputName2').val("");
	$("#sub1").hide();
	$("#sub2").show();
	$("#agcstable").html("");
	getTime();
}

function getTime(value){
	$.post('../agcs/findAllTime',{search:value},function(data){
		if(data!=null&&data!=""){
			 $("#agcsforms").html("");
			 var html='<table class="table table-hover">';
			 html +='<caption>为未能自动安排课表的教室和时间</caption>';
			 html +='<tr>';
			 html +='<th style="text-align: center;">编号</th>';
			 html +='<th style="text-align: center;">教室编号</th>';
			 html +='<th style="text-align: center;">教室类型</th>';
			 html +='<th style="text-align: center;">教室容量</th>';
			 html +='<th style="text-align: center;">星期</th>';
			 html +='<th style="text-align: center;">节次</th>';
			 html +='<th style="text-align: center;">操作</th>';
			 html +='</tr>';
			 for (var i = 0; i < data.length; i++) { 
				 html +='<tr  style="text-align: center;">';
				 html +='	<td >'+(i+1)+'</td>';
				 html +='	<td >'+data[i].classroom.serialNumber+'</td>';
				 html +='	<td >'+data[i].classroom.type.name+'</td>';
				 html +='	<td >'+data[i].classroom.capacity+'</td>';
				 html +='	<td >'+data[i].jcb.xq+'</td>';
				 html +='	<td >'+data[i].jcb.jcsj+'</td>';
				 html +='	<td><button type="button" class="btn btn-warning" onclick="timedelete('+data[i].id+')">删除</button></td>';
				 html +='</tr>';
		     }
			html +='</table>';
			$("#agcstable").html(html);
		}
	});
}
function getWinto(value){
	$.post('../agcs/findAlls',{search:value},function(data){
		if(data!=null&&data!=""){
			 $("#agcsforms").html("");
			 var html='<table class="table table-hover">';
			 html +='<caption>为未能自动安排课表的课程</caption>';
			 html +='<tr>';
			 html +='<th style="text-align: center;">编号</th>';
			 html +='<th style="text-align: center;">学年学期</th>';
			 html +='<th style="text-align: center;">课程名称</th>';
			 html +='<th style="text-align: center;">课程代码</th>';
			 html +='<th style="text-align: center;">任课老师</th>';
			 html +='<th style="text-align: center;">年级</th>';
			 html +='<th style="text-align: center;">任课班级</th>';
			 html +='<th style="text-align: center;">总人数</th>';
			 html +='<th style="text-align: center;">需要安排的教室类型</th>';
			 html +='<th style="text-align: center;">未生成原因</th>';
			 html +='<th style="text-align: center;">操作</th>';
			 html +='</tr>';
			 for (var i = 0; i < data.length; i++) { 
				 html +='<tr  style="text-align: center;">';
				 html +='	<td >'+(i+1)+'</td>';
				 html +='	<td >'+data[i].ed.schoolyear.xnxq+'</td>';
				 html +='	<td >'+data[i].ed.curriculum.kcmc+'</td>';
				 html +='	<td >'+data[i].ed.curriculum.kcdm+'</td>';
				 html +='	<td >'+data[i].ed.teacher.name+'</td>';
				 html +='	<td >'+data[i].ed.curriculum.profession.year+'</td>';
				 html +='	<td >'+data[i].ed.bj+'</td>';
				 html +='	<td >'+data[i].ed.tbclassNumbers+'</td>';
				 html +='	<td >'+data[i].ed.jslx+'</td>';
				 html +='	<td >'+data[i].records+'</td>';
				 html +='	<td><button type="button" class="btn btn-warning" onclick="eddelete('+data[i].id+')">删除</button></td>';
				 html +='</tr>';
		     }
			html +='</table>';
			$("#agcstable").html(html);
		}
	});
}
function timedelete(value){
	bootbox.confirm({
		buttons: {
			confirm: {
				label: '取消',
				className: 'btn-myStyle'
			},
			cancel: {
				label: '确认',
				className: 'btn-default'
			}
		},
		message: '是否删除？',
		callback: function(result) {
			if(result) {
				
			} else {
				$.post('../agcs/timedelete',{id:value},function(data){
					if(data.success){
						getTime();
						bootbox.alert({
						    buttons: {
							   ok: {
								    label: 'ok',
								    className: 'btn-default'
							    }
						    },
						    message: '删除成功！',
						    callback: function() {
							    
						    },
						    title: "提示",
					    });
						
					}else{
						bootbox.confirm("删除失败", function(result){ });
					}
				});
			}
		},
		title: "提示",
	});
}
function eddelete(value){
	bootbox.confirm({
		buttons: {
			confirm: {
				label: '取消',
				className: 'btn-myStyle'
			},
			cancel: {
				label: '确认',
				className: 'btn-default'
			}
		},
		message: '是否删除？',
		callback: function(result) {
			if(result) {
				
			} else {
				$.post('../agcs/eddelete',{id:value},function(data){
					if(data.success){
						
						getWinto();
						bootbox.alert({
						    buttons: {
							   ok: {
								    label: 'ok',
								    className: 'btn-default'
							    }
						    },
						    message: '删除成功！',
						    callback: function() {
							    
						    },
						    title: "提示",
					    });
					}else{
						bootbox.confirm("删除失败", function(result){ });
					}
				});
			}
		},
		title: "提示",
	});
	
}
</script>
</html>